package org.ntu.rtsearch.index;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.ntu.rtsearch.index.model.Tweet;

public class TweetReader {
	
	private BufferedReader br;
	
	public TweetReader(File dir, String fileName) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(new File(dir, fileName)));
	}
	
	public Tweet next() throws IOException {
		String line = br.readLine();
		return (line == null) ? null : new Tweet(line);
	}
	
	public void close() throws IOException {
		if(br != null) {
			br.close();
		}
	}
	
	public static void main(String[] args) throws IOException {
		TweetReader reader = new TweetReader(new File("c:\\rtsearch_data\\"), "tweet.processed");
		
		Tweet tweet = null;
		int cnt = 0;
		while((tweet = reader.next()) != null) {
			System.out.println(tweet.getText());
			System.out.println(tweet.getUserId());
			System.out.println(tweet.getIsFav());
			System.out.println(tweet.getRtCount());
			System.out.println(tweet.getTimeStamp());;
			cnt++;
			System.out.println(cnt);
		}
		
		reader.close();
	}
}
